import './public-path'
import './assets/main.css'
import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'

// const app = createApp(App)

// app.use(createPinia())
// app.use(router)

// app.mount('#app')
import {
    renderWithQiankun,
    qiankunWindow,
    type QiankunProps
  } from 'vite-plugin-qiankun/dist/helper'
  
  // @ts-ignore
  let app
  // @ts-ignore
  const render = (container) => {
    app = createApp(App)
    app
      .use(router)
      .use(createPinia())
      .mount(container ? container.querySelector('#app') : '#app')
  }
  
  const initQianKun = () => {
    renderWithQiankun({
        mount(props) {
            const { container } = props
            render(container)
        },
        bootstrap() { },
        unmount() {
            // @ts-ignore
            app.unmount()
        },
        update: function (props: QiankunProps): void | Promise<void> {
            throw new Error('Function not implemented.')
        }
    })
  }
  
  qiankunWindow.__POWERED_BY_QIANKUN__ ? initQianKun() : render(app)